package com.itcast.cn.response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/responseDemo1")
public class ResponseDemo1 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        System.out.println("进来了资源项");

//        //重定向
//        //1.设置响应码302
//        response.setStatus(302);
//        //2.设置相应头Location，其中"Location"单词是固定的
//        response.setHeader("Location","/haha/responseDemo2");

        //Redirect    重新使用
        response.sendRedirect(request.getContextPath()+"/responseDemo2");
//        response.sendRedirect("http://www.baidu.com");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
